class DospyWatersController < ApplicationController
  layout 'base.html', :except => [:create,:show]

  # admin
  before_filter :authorize_for_admin
  
  def new
    @forums = {
      '3230' => 'forum-136-1.html',
      'N70' => 'forum-52-1.html',
      'N72' => 'forum-52-1.html',
      '6102' => 'forum-82-1.html',
      '5320' => 'forum-193-1.html',
      'E50' => 'forum-193-1.html',
      'E63' => 'forum-236-1.html',
      'E71' => 'forum-249-1.html',
      'E72' => 'forum-286-1.html',
      'E73' => 'forum-136-1.html',
      'N78' => 'forum-222-1.html',
      'N79' => 'forum-246-1.html',
      'N95' => 'forum-147-1.html'
    }
    @today_tasks = DospyWaterTask.find_all_by_created_on(Date.today)
    def @today_tasks.find_by_forum_code(forum_code)
      self.each do |task|
        return task if task.forum_code == forum_code
      end
      return nil
    end
  end

  def create          
    @task = DospyWaterTask.find_or_initialize_by_forum_code_and_created_on(params[:task][:forum_code],Date.today)
    @task.rewater! params[:task]
    render :show, :format => :js
  end
  
  def show
    @task = DospyWaterTask.find(params[:id])
  end

end
